home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / GNU-SMALLTALK.lha / examples / suntool.st < prev    next >
Text File  |  1992-02-15  |  6KB  |  203 lines

  1. "Provide some example interface to SunView.  See the comment in win.c
  2. for details."
  3.  
  4. "======================================================================
  5. |
  6. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  7. | Written by Steve Byrne.
  8. |
  9. | This file is part of GNU Smalltalk.
  10. |
  11. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  12. | under the terms of the GNU General Public License as published by the Free
  13. | Software Foundation; either version 1, or (at your option) any later version.
  14. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  15. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  17. | details.
  18. | You should have received a copy of the GNU General Public License along with
  19. | GNU Smalltalk; see the file LICENSE.  If not, write to the Free Software
  20. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  21. |
  22.  ======================================================================"
  23.  
  24.  
  25.  
  26. "| pairs |
  27.     pairs _ #((Frame            'FRAME')
  28.           (Panel            'PANEL')
  29.           (PanelMessage    'PANEL_MESSAGE')
  30.           (PanelButton    'PANEL_BUTTON')
  31.           (PanelChoice    'PANEL_CHOICE')
  32.           (PanelSlider    'PANEL_SLIDER')
  33.           (PanelText    'PANEL_TEXT')
  34.           (PanelToggle    'PANEL_TOGGLE')
  35.           (PanelLine    'PANEL_LINE')
  36.          ).
  37.     pairs do:
  38.         [ :aPair | SuntoolObjectTypes at: (aPair at: 1)
  39.                          put: (Smalltalk lookupCAddr: (aPair at: 2)) ]!"
  40.  
  41. Object subclass: #Suntools
  42.     instanceVariableNames: 'stObject'
  43.     classVariableNames: ''
  44.     poolDictionaries: 'SuntoolObjectTypes WindowAttrs'
  45.     category: 'Cool hacking'!
  46.  
  47. Suntools subclass: #Window
  48.     instanceVariableNames: ''
  49.     classVariableNames: ''
  50.     poolDictionaries: ''
  51.     category: 'Cool hacking'.
  52.  
  53. Suntools subclass: #Frame
  54.     instanceVariableNames: ''
  55.     classVariableNames: ''
  56.     poolDictionaries: 'FrameAttrs' "Maybe WindowAttrs too?"
  57.     category: 'Cool hacking'.
  58.  
  59. Suntools subclass: #Panel
  60.     instanceVariableNames: ''
  61.     classVariableNames: ''
  62.     poolDictionaries: 'PanelAttrs'
  63.     category: 'Cool hacking'.
  64.  
  65. Suntools subclass: #PanelItem
  66.     instanceVariableNames: ''
  67.     classVariableNames: ''
  68.     poolDictionaries: 'PanelAttrs'
  69.     category: 'Cool hacking'.
  70.  
  71. Suntools subclass: #Textsw
  72.     instanceVariableNames: ''
  73.     classVariableNames: ''
  74.     poolDictionaries: 'TextswAttrs'
  75.     category: 'Cool hacking'.
  76.  
  77. Suntools subclass: #Canvas
  78.     instanceVariableNames: ''
  79.     classVariableNames: ''
  80.     poolDictionaries: 'CanvasAttrs'
  81.     category: 'Cool hacking'.
  82.  
  83. Suntools subclass: #Develop
  84.     instanceVariableNames: ''
  85.     classVariableNames: ''
  86.     poolDictionaries: 'CanvasAttrs TextswAttrs PanelAttrs FrameAttrs SuntoolObjectTypes WindowAttrs'
  87.     category: 'Cool hacking'!
  88.  
  89.  
  90. 'about to create a window' printNl!
  91.  
  92. Behavior defineCFunc: 'windowCreate'
  93.          withSelectorArgs: 'windowCreate: parent type: aType attrs: anArray'
  94.      forClass: Suntools class
  95.      returning: #cObject
  96.      args: #(cObject cObject variadic)
  97. !
  98.  
  99. !Suntools class methodsFor: 'instance creation'!
  100.  
  101. createWindowObject: parent type: objectType attrs: anArray
  102.     | parentObject |
  103.     parentObject _ parent isNil ifTrue:  [ nil ]
  104.                             ifFalse: [ parent stObject ].
  105.     ^self newObject: (self windowCreate: parentObject type: objectType attrs: anArray)
  106. !
  107.  
  108. newObject: suntoolsObject
  109.     ^(self new) stObject: suntoolsObject
  110. !!
  111.  
  112.  
  113. !Suntools methodsFor: 'private'!
  114.  
  115. stObject
  116.     ^stObject
  117. !
  118.  
  119. stObject: suntoolsObject
  120.     stObject _ suntoolsObject
  121. !!
  122.  
  123.  
  124. Behavior defineCFunc: 'windowLoop'
  125.          withSelectorArgs: 'windowLoop: frame'
  126.          forClass: Frame
  127.      returning: #void
  128.      args: #(cObject)
  129. !
  130.  
  131. !Frame class methodsFor: 'instance creation'!
  132.  
  133. create: parent attributes: anArray
  134.     ^self createWindowObject: parent type: FrameType attrs: anArray
  135. !!
  136.  
  137. !Frame methodsFor: 'processing'!
  138.  
  139. windowMainLoop
  140.     self windowLoop: stObject
  141. !!
  142.  
  143. !Panel class methodsFor: 'instance creation'!
  144.  
  145. create: parent attributes: anArray
  146.     ^self createWindowObject: parent type: PanelType attrs: anArray
  147. !!
  148.  
  149. Behavior defineCFunc: 'panelCreateItem'
  150.          withSelectorArgs: 'panelCreateItem: panel type: aType attrs: anArray'
  151.      forClass: Panel
  152.      returning: #cObject
  153.      args: #(cObject cObject variadic)!
  154.  
  155. !Panel methodsFor: 'processing'!
  156.  
  157. createItem: type attributes: anArray
  158.     "not right"
  159.     ^self panelCreateItem: stObject type: type attrs: anArray
  160. !!    
  161.  
  162. !Develop class methodsFor: 'test'!
  163.  
  164. test
  165. | frame aStream panel |
  166.     aStream _ WriteStream on: (Array new: 0).
  167.     aStream nextPut: frameLabel.  aStream nextPut: 'Test window'.
  168.     aStream nextPut: 0.
  169.     frame _ Frame create: nil attributes: aStream contents.
  170.     aStream _ WriteStream on: (Array new: 3).
  171.     aStream nextPut: panelLayout.
  172.     aStream nextPut: (Smalltalk lookupCAddr: 'PANEL_VERTICAL').
  173.     aStream nextPut: 0.
  174.     panel _ Panel create: frame attributes: aStream contents.
  175.     
  176.  
  177.     aStream _ WriteStream on: (Array new: 0).
  178.     aStream nextPut: panelLabelString.
  179.     aStream nextPut: 'Rambo'.
  180.     aStream nextPut: panelChoiceStrings.
  181.         aStream nextPut: 'foo'.
  182.         aStream nextPut: 'bar'.
  183.         aStream nextPut: 'baz'.
  184.     aStream nextPut: 0.
  185.     aStream nextPut: 0.
  186.     panel createItem: PanelChoiceType attributes: aStream contents.    
  187.  
  188.     aStream _ WriteStream on: (Array new: 0).
  189.     aStream nextPut: panelLabelString.    aStream nextPut: 'Brightness: '.
  190.     aStream nextPut: panelValue.          aStream nextPut: 75.
  191.     aStream nextPut: panelMinValue.       aStream nextPut: 0. 
  192.     aStream nextPut: panelMaxValue.       aStream nextPut: 100.
  193.     aStream nextPut: panelSliderWidth.      aStream nextPut: 300.
  194.     panel createItem: PanelSliderType attributes: aStream contents.
  195.     frame windowMainLoop
  196. !!
  197.  
  198. Develop test!
  199.  
  200.  
  201.